package com.fairytask.ui.item
{
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Text;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.resource.StaticIni;
	import com.fairytask.ui.skillUnit.ChartUI;
	
	import flash.display.DisplayObject;
	
	/**
	 * 命格Item 
	 * @author xujh
	 * 
	 */
	public class ChartItem extends BaseItem
	{
		//箭头
		public static const CHEQUER_UP		:int = 0;	//上
		public static const CHEQUER_RIGHT		:int = 1;	//右
		public static const CHEQUER_DOWN		:int = 2;	//下
		public static const CHEQUER_LEFT		:int = 3;	//左
		//格子类型
		public static const CHEQUER_EMPTY		:int = 1;	//空白
		public static const CHEQUER_MONEY		:int = 2;	//银两
		public static const CHEQUER_CHART		:int = 3;	//命格
		public static const CHEQUER_DEAD		:int = 4;	//死亡	
			
		private var direcMc	:Clip;	//路径
		private var chartMc	:Clip;	//命格
		private var moneyTxt	:Text;	//获取金钱
		private var deadMc		:Clip;	//死亡
		
		private var _curPrize	:DisplayObject;	//当前奖励
		private var _chartID	:int;
		private var _prize		:int;
		
		public function ChartItem()
		{
			super();
		}
		
		/**
		 * 设置数据 
		 * @param type 类型
		 * @param direc 方向
		 * @param val 获取的金钱/命格
		 * 
		 */
		public function setData(type:int,direc:int,val:int):void
		{
			switch(type)
			{
				case CHEQUER_EMPTY:		//空白直接显示方向
					direcArrow(direc);
					break;
				case CHEQUER_MONEY:		//银两
					getMoney(val);
					direcArrow(direc);
					break;
				case CHEQUER_CHART:		//命格
					chartItem(val);
					direcArrow(direc);
					break;
				case CHEQUER_DEAD:		//死亡直接显示死亡图片
					isDead();
					break;
			}
		}
		
		/**
		 * 获取奖励 
		 * 
		 */
		public function pickPrize():void
		{
			if(null != _curPrize)
			{
				this.removeChild(_curPrize);
				_chartID = 0;
				_prize = 0;
			}
		}
		
		/**
		 * 获取奖励物品 
		 * @return 
		 * 
		 */
		public function get curPrize():DisplayObject
		{
			return _curPrize;
		}
		
		public function get prize():int
		{
			return _prize;
		}
		
		/**
		 * 清除内容 
		 * 
		 */
		public function clearItem():void
		{
			_curPrize = null;
			_chartID = 0;
			_prize = 0;
			while(this.numChildren>0)
			{
				this.removeChildAt(0);
			}
		}
		
		/**
		 * 获取命格id 
		 * @return 
		 * 
		 */
		public function get chartID():int
		{
			return _chartID;
		}
		
		/**
		 * 死亡 
		 * 
		 */
		private function isDead():void
		{
			deadMc = new Clip();
			deadMc.source = ResConfig.pngResPath + "locked.png";
			deadMc.x	=	-5;
			deadMc.y	=	-8;
			addChild(deadMc);
			//命格死亡
			ChartUI.getInstance().isDead = true;
		}
		
		/**
		 * 设置方向 
		 * @param val
		 * 
		 */
		private function direcArrow(val:int):void
		{
			if(val == -1)
			{
				return;
			}
			direcMc = new Clip();
			direcMc.source = ResConfig.pngResPath + "arrow_" + (val+1) + ".png";
			direcMc.x = 14;
			direcMc.y = 17;
			addChild(direcMc);
		}
		
		/**
		 * 设置命格物品 
		 * @param val
		 * 
		 */
		private function chartItem(val:int):void
		{
			chartMc = new Clip();
			if(val == 0)
			{
				return;
			}
			_chartID = val;
			chartMc.source = ResConfig.iconPath + StaticIni.getIniVar(_chartID,"Icon") + ResConfig.iconImg;
			chartMc.x = 2;
			chartMc.y = 3;
			addChild(chartMc);
			_curPrize = chartMc;
			_prize = 1;
			chartMc.filters = null;
		}
		
		/**
		 * 获得的金钱 
		 * @param val
		 * 
		 */
		private function getMoney(val:int):void
		{
			moneyTxt = new Text(60,50,"vScrol_6","vScrol_7",false);
			moneyTxt.htmlStr = "获得银两<br>" + val;
			addChild(moneyTxt);
			_curPrize = moneyTxt;
			_prize = 2;
		}
		
		/**
		 * 添加死亡滤镜（变灰） 
		 * 
		 */
		public function addFilter():void
		{
			direcMc.filters = [Filter.GRAY];
		}
		
		/**
		 * 移除滤镜 
		 * 
		 */
		public function delFilter():void
		{
			direcMc.filters = null;
		}
	}
}